package com.erp.framework.controller.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import com.erp.framework.controller.form.SimpleSearchStyleForm;
import com.erp.framework.pagination.PageControl;
import com.erp.framework.pagination.Pageable;

//import com.apexpro.object.common.pagination.PageControl;
//import com.apexpro.object.common.pagination.Pageable;
//import com.apexpro.object.web.form.BaseSearchForm;

public class CustomPageTag extends TagSupport {
	private String id = null;
	private String name = null;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}	
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int doStartTag() throws JspException {
		SimpleSearchStyleForm search_form = (SimpleSearchStyleForm)pageContext.getAttribute(name, PageContext.SESSION_SCOPE);
		
		if (name == null)
			throw new JspException("Unable to locate bean " + name);
		
		PageControl pc = search_form.getPageControl();
		
		if (pc == null)
			return SKIP_BODY;
		
		Pageable page = pc.getCurrentPage();
		pageContext.setAttribute(id, page, PageContext.PAGE_SCOPE);
		
		return EVAL_BODY_INCLUDE;
	}
}
